Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
oniyi-http-client
Advanced tools
Adding a plugin interface to "request" that allows modifications of request parameters and response data
Adding a plugin interface to request that allows modifications of request parameters and response data
$ npm install --save oniyi-http-client
Note: this module does not support streams, yet
var OniyiHttpClient = require('oniyi-http-client');
var client = new OniyiHttpClient({
defaults: {
headers: {
'Accept-Language': 'en-US,en;q=0.8',
Host: 'httpbin.org',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
}
}
});
client.makeRequest('http://httpbin.org/headers', {
method: 'GET'
// jar: client.jar(new redisStore(redisClient))
}, function (err, response, body) {
if (err) {
logger.warn('got an error');
if (err.stack) {
logger.error(err.stack);
} else {
logger.error(err);
}
process.exit(0);
}
if (response) {
logger.debug('statusCode: %d', response.statusCode);
logger.debug('headers: ', response.headers);
logger.debug('body: ', body);
}
process.exit(0);
});
This creates a plugin named plugin-2
which adds a request-header with name and value plugin-2
.
Also, it stores some data in a local variable and overrides the original callback function
to print that stored data on response. Afterwards it calls the original callback function.
var plugin2 = {
name: 'plugin-2',
load: function (req, params, callback) {
var plugin2Storage = {};
setTimeout(function () {
params.headers = params.headers || {};
params.headers['plugin-2'] = 'plugin-2';
var name = 'Bam Bam!';
var originalCallback = params.callback;
params.callback = function (err, response, body) {
logger.info('Name in this plugin\'s store: %s', name);
return originalCallback(err, response, body);
};
callback(null, params);
}, 500);
}
};
client
.use(plugin2)
.makeRequest('http://httpbin.org/headers', {
method: 'GET'
// jar: client.jar(new redisStore(redisClient))
}, function (err, response, body) {
if (err) {
logger.warn('got an error');
if (err.stack) {
logger.error(err.stack);
} else {
logger.error(err);
}
process.exit(0);
}
if (response) {
logger.debug('statusCode: %d', response.statusCode);
logger.debug('headers: ', response.headers);
logger.debug('body: ', body);
}
process.exit(0);
});
MIT © Benjamin Kroeger
FAQs
Adding a plugin interface to "request" that allows modifications of request parameters and response data
The npm package oniyi-http-client receives a total of 3 weekly downloads. As such, oniyi-http-client popularity was classified as not popular.
We found that oniyi-http-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.